package org.hgvc.webapp.ets.jsf.beans.agent;

import java.util.List;

import javax.faces.component.UIParameter;
import javax.faces.event.ActionEvent;

import org.hgvc.webapp.ets.bo.Agreement;
import org.hgvc.webapp.ets.bo.Invoice;
import org.hgvc.webapp.ets.constant.CommonConstant;
import org.hgvc.webapp.ets.spring.service.MemberService;
import org.jocsb.base.AbstractBean;
import org.jocsb.base.exception.BaseException;
import org.jocsb.base.util.FacesUtils;



public class AgentMemberAgreementInvoiceBean extends AbstractBean {

	public static final String BEAN_NAME="agentMemberAgreementInvoiceBean";
	public static final String NAV_VIEW_INVOICE="agentMemberViewAgreementInv";
	private Agreement agreement;
	private MemberService service;
	//private List<InvoiceDtl> invoiceDtlList;
	private List<Invoice> invoiceList;
	private Invoice invoice;
	
	private String flag = CommonConstant.INVOICE_STATUS_ACTIVE;
	
	
	public String getFlag() {
		return flag;
	}

	public Invoice getInvoice() {
		return invoice;
	}

	public void setInvoice(Invoice invoice) {
		this.invoice = invoice;
	}

	public Agreement getAgreement() {
		return agreement;
	}

	public void setAgreement(Agreement agreement) {
		this.agreement = agreement;
	}

	public void setService(MemberService service) {
		this.service = service;
	}

	
	
	/*-----------------------------------------------------------*/
	
	public String navListAction(Agreement agreement){
		this.agreement = agreement;
		return NAV_VIEW_INVOICE;
	}

	public List<Invoice> getInvoiceList() {
		try{
			invoiceList = service.getInvoiceByAgreementId(agreement.getAgreementId());
		}catch(BaseException be){
			be.printStackTrace();
			initErrorBean(be);
		}
		
		
		return invoiceList;
	}
	
	public void memberPaymentListener(ActionEvent actionEvent){
		UIParameter param = (UIParameter)actionEvent.getComponent().findComponent("invoiceId");
		String id = (String)param.getValue();
		
		for(Invoice in:invoiceList){
			if(in.getInvoiceId().equalsIgnoreCase(id)){
				invoice = in;
				break;
			}
		}
	}
	
	public String memberPaymentNavigate(){
		AgentMemberInovicePaymentBean bean = (AgentMemberInovicePaymentBean)FacesUtils.getManagedBean(AgentMemberInovicePaymentBean.BEAN_NAME);
		return bean.navigateInvoicePayment(agreement, invoice, invoice.getInvoiceDtl());
	}
	
	/*public List<InvoiceDtl> getInvoiceDtlList() {
		try{
			System.out.println(" start---------------------->>> ");
			invoiceDtlList = service.getInvoiceDtlByAgreementId(agreement.getAgreementId());
			System.out.println(" invoiceDtlList---------------------->>> "+invoiceDtlList.size());
		}catch(BaseException be){
			be.printStackTrace();
			initErrorBean(be);
		}
		return invoiceDtlList;
	}*/
	
	
}
